<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<script type="text/javascript">
function Master() {
	var _this = this;
	this.init = function() {
		$('#save').click(function(){
			_this.save();
		});
		var gids = $('#gids').val().split(',');
		if(gids.length > 0) {
			for(var i=0; i<gids.length; i++) {
				$('#'+gids[i]).addClass('slt');
			}
		}
		$('td').find('em').each(function(){
			$(this).click(function(){
				var gids = $('#gids').val();
				var id = $(this).attr('id');
				if(gids.indexOf(id+',') != -1) {
					$('#gids').val(gids.replace(id+',',''));
					$(this).removeClass('slt');
				} else {
					$('#gids').val(gids + (id+','));
					$(this).addClass('slt');
				}
			});
		});
	};
	this.save = function() {
		$('#save').attr('disabled', 'disabled');
		var url='/a/ajax/master/save';
		var id = $('#id').val();
		var name = $('#name').val();
		var password = $('#password').val();
		var gids = $('#gids').val();
		$.ajax({
			url:url
			, type:'POST'
			, data:{id:id,nm:name,pwd:password,gids:gids}
			, success:function(data){
				var json = $.parseJSON(data);
				if(json.succeed) {
					window.location = "/a/staff/master/list";
				} else {
					alert(json.msg);
				}
				$('#save').removeAttr('disabled');
			}
			,error:function() {
				alert(MSG.ERR);
				$('#save').removeAttr('disabled');
			}
		});
	}
};
var master = new Master();
$(function(){
	master.init();
	$(document).keydown(function(){
		if(event.keyCode == KEY.ENTER) {
			master.save();
		}
	});
	$('#name').focus();
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="form">
<table>
<tr>
<th>登录名称</th>
<td>
<input type="text" id="name" name="name" value="${master.name}" />
</td>
</tr>
<tr>
<th>登录密码</th>
<td>
<input type="text" id="password" name="password" value="${master.password}" />
</td>
</tr>
<tr>
<th>选择所在组</th>
<td class="select">
<c:forEach var="group" items="${groups}">
<em id="${group.id}">${group.name}</em>
</c:forEach>
</td>
</tr>
<!--  -->
<tr>
<th></th>
<td>
<input type="hidden" id="id" name="id" value="${master.id}" />
<input type="hidden" id="gids" name="gids" value="<c:forEach var="group" items="${mGroups}">${group.id},</c:forEach>" />
<input type="button" id="save" name="save" value="确定保存" />
<input type="hidden" id="backURL" name="backURL" value="${backURL}" />
</td>
</tr>
</table>
</div>
<div class="sidebarMenu">
<ul>
<li><a href="/a/staff/master/list">管理员列表</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>